# -*- coding: utf-8 -*-

"""
@Author: 芮芪懿 QQ1849433491
@Project->File: pygame_train -> 3动态背景.py
@IDE：PyCharm 2020.1
@File: 3动态背景.py
@Datetime: 2021/7/7 19:58
"""
import pygame
from resource_path import *

pygame.init()
screen = pygame.display.set_mode((480, 800))  # 屏幕对象,宽高素材一致
# 1> 加载图像数据
bgImage = pygame.image.load(bgImagePath)
# bgImage2 = pygame.image.load(bgImagePath)
# 2> blit 绘制图像
screen.blit(bgImage, (0, 0))
screen.blit(bgImage, (0, -bgImage.get_rect().height))
# 3> update 更新屏幕显示
pygame.display.update()
imageYStartPosition = 0  # 背景y轴初始位置
imageYStartPosition2 = - bgImage.get_rect().height  # 背景y轴初始位置
clock = pygame.time.Clock()  # 创建时钟对象
while True:
    clock.tick(60)
    imageYStartPosition += 2
    imageYStartPosition2 += 2
    screen.blit(bgImage, (0, imageYStartPosition))
    screen.blit(bgImage, (0, imageYStartPosition2))
    if imageYStartPosition >= bgImage.get_rect().height or imageYStartPosition2 >= bgImage.get_rect().height:
        imageYStartPosition = 0
        imageYStartPosition2 = - bgImage.get_rect().height
    # print(bgImage.get_rect())
    pygame.display.update()  # 更新屏幕显示
    pass
pygame.quit()